package vista;

import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectOutputStream;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;
import modelo.Moto;
import modelo.MotoManager;

/**
 * Clase para manejar los ficheros text y xml
 * @author Mª Luz García Rodríguez
 * @author Luis Massó Saiz
 */
public class JFrameFicheros extends javax.swing.JFrame {

    String filename;
    MotoManager myManager;
    boolean flagIsTexto;

    /**
     * Creates new form JFrameMain
     */
    public JFrameFicheros() {
        initComponents();

        filename = "";
        myManager = new MotoManager();
        this.setLocationRelativeTo(null);
        //this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    }

    // MÉTODO PARA CREAR ARCHIVO BINARIO. BORRABLE CUANDO ESTÉ TERMINADO
    private void crearArchivoBinario() throws IOException {
        ArrayList<Moto> exposicion2 = new ArrayList<>();

        exposicion2.add(new Moto("Honda", "CBR 1000 RR Fireblade", 1000, 178.2, 4, "Liquida", 16119, "honda1100rr.jpeg"));
        exposicion2.add(new Moto("Honda", "MSX 125", 125, 9.8, 1, "Aire", 3699, "hondamsx125.jpeg"));
        exposicion2.add(new Moto("Honda", "CRF 250X", 249, 29.8, 1, "Liquida", 7839, "hondacrf250x.jpeg"));
        exposicion2.add(new Moto("Honda", "CRF  50F", 49, 3, 1, "Aire", 2129, "hondacrf50f.jpeg"));
        exposicion2.add(new Moto("Honda", "VT 750 S", 745, 44, 2, "Liquida", 7489, "hondavt750s.jpeg"));
        exposicion2.add(new Moto("Yamaha", "X enter 125 Moto Gp", 125, 12.2, 1, "Liquida", 3179, "yamahaxenter125motogp.jpeg"));
        exposicion2.add(new Moto("Yamaha", "X Max 250", 250, 20.4, 1, "Liquida", 4999, "yamahaxmax250.jpeg"));
        exposicion2.add(new Moto("Yamaha", "XJ6 Diversion F ABS", 600, 77.5, 4, "Liquida", 8799, "yamahaxj6diversionfabs.jpeg"));
        exposicion2.add(new Moto("Yamaha", "YBR 125", 124, 10, 1, "Aire", 2619, "yamahaybr125.jpeg"));
        exposicion2.add(new Moto("Yamaha", "XT 660 X", 660, 48, 1, "Liquida", 7199, "yamahaxt660x.jpeg"));
        exposicion2.add(new Moto("Triumph", "Daytona 675", 675, 131, 3, "Liquida", 10695, "triumphdaytona675.jpeg"));
        exposicion2.add(new Moto("Triumph", "Spring GT", 1050, 128, 3, "Liquida", 13695, "triumphspringgt.jpeg"));
        exposicion2.add(new Moto("Triumph", "Bonneville SE", 865, 67, 2, "Aire", 8995, "triumphbonnevillese.jpeg"));
        exposicion2.add(new Moto("Triumph", "Bonneville T100 Especial Edition", 865, 68, 2, "Aire", 9865, "triumphbonnevillet100ee.jpeg"));
        exposicion2.add(new Moto("Triumph", "Street Triple R ABS", 675, 106, 3, "Liquida", 8695, "triumphstreettriplerabs.jpeg"));
        exposicion2.add(new Moto("Harley Davidson", "Dyna Street Bob", 1584, 0, 2, "Aire", 14850, "harleydynastreetbob.jpeg"));
        exposicion2.add(new Moto("Harley Davidson", "Dyna Wide Glide", 1585, 0, 2, "Aire", 17600, "dynawideglide.jpeg"));
        exposicion2.add(new Moto("Harley Davidson", "Sportster Seventy-Two", 1202, 0, 2, "Aire", 12400, "sportsterseventytwo.jpeg"));
        exposicion2.add(new Moto("Harley Davidson", "Sportster Superlow 1200T", 1203, 67, 2, "Aire", 12750, "sportstersuperlow1200t.jpeg"));
        exposicion2.add(new Moto("Harley Davidson", "VRSC V-Rod Muscle", 1246, 112, 2, "Liquida", 20250, "vrscvrodmuscle.jpeg"));
        exposicion2.add(new Moto("Moto Guzzi", "Norge 850", 850, 72.1, 2, "Aire", 12030, "guzzinorge850.jpeg"));
        exposicion2.add(new Moto("Moto Guzzi", "Breva 750", 744, 48.3, 2, "Aire", 7990, "guzzibreva750.jpeg"));
        exposicion2.add(new Moto("Moto Guzzi", "V7 Cafe Classic", 744, 48.8, 2, "Aire", 0, "guzziv7cafeclassic.jpeg"));
        exposicion2.add(new Moto("Moto Guzzi", "Stelvio 1200 NTX", 1151, 102, 2, "Aire", 14990, "guzzistelvio1200ntx.jpeg"));
        exposicion2.add(new Moto("Moto Guzzi", "V7 Clubman Racer", 744, 48.8, 2, "Aire", 9890, "v7clubmanracer.jpeg"));

        String fileName2 = "Motos.dat";
        try {
            FileOutputStream outputStream = new FileOutputStream(fileName2);
            ObjectOutputStream writer = new ObjectOutputStream(outputStream);

            writer.writeObject(exposicion2);

            writer.close();
            outputStream.close();
        } catch (Exception ex) {
            throw new IOException("Error escribiendo el archivo");
        }
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents()
    {

        jMenu2 = new javax.swing.JMenu();
        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea = new javax.swing.JTextArea();
        jLabelmensaje = new javax.swing.JLabel();
        jButtonMostrarDOM = new javax.swing.JButton();
        BtnGuardar = new javax.swing.JButton();
        BtnMostrarDom = new javax.swing.JButton();
        jPanelDatos = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jTextFieldMarca = new javax.swing.JTextField();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jTextFieldCilindrada = new javax.swing.JTextField();
        jTextFieldModelo = new javax.swing.JTextField();
        jLabel4 = new javax.swing.JLabel();
        jTextFieldPotencia = new javax.swing.JTextField();
        jLabel5 = new javax.swing.JLabel();
        jTextFieldCilindros = new javax.swing.JTextField();
        jLabel6 = new javax.swing.JLabel();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jTextFieldRefrigeracion = new javax.swing.JTextField();
        jLabel9 = new javax.swing.JLabel();
        jTextFieldPrecio = new javax.swing.JTextField();
        jPanelImage = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        BtnMostrarTexto = new javax.swing.JButton();
        BtnMostrarBinario = new javax.swing.JButton();
        BtnMostrarSax = new javax.swing.JButton();
        BtnAnyadir = new javax.swing.JButton();
        BtnMostrarArray = new javax.swing.JButton();
        BtnMostrarXml = new javax.swing.JButton();
        BtnCancelar = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        jMenu3 = new javax.swing.JMenu();
        MenuAbrirDom = new javax.swing.JMenuItem();
        MenuAbrirSax = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        MenuAbrirTexto = new javax.swing.JMenuItem();
        MenuAbrirBinario = new javax.swing.JMenuItem();
        jMenu1 = new javax.swing.JMenu();
        MenuCrearBD = new javax.swing.JMenuItem();
        MenuConectarBD = new javax.swing.JMenuItem();
        MenuDesconectarBD = new javax.swing.JMenuItem();
        MenuEjecutarComandoBD = new javax.swing.JMenuItem();
        MenuRenombrarBD = new javax.swing.JMenuItem();
        MenuPropiedadesBD = new javax.swing.JMenuItem();
        MenuSalir = new javax.swing.JMenu();
        MenuSalirSalir = new javax.swing.JMenuItem();

        jMenu2.setText("jMenu2");

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);

        jTextArea.setEditable(false);
        jTextArea.setColumns(20);
        jTextArea.setRows(5);
        jTextArea.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jScrollPane1.setViewportView(jTextArea);

        jLabelmensaje.setBackground(new java.awt.Color(255, 255, 153));
        jLabelmensaje.setText("<Fichero XML no seleccionado>");

        jButtonMostrarDOM.setText("Muestra contenido DOM");
        jButtonMostrarDOM.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                jButtonMostrarDOMActionPerformed(evt);
            }
        });

        BtnGuardar.setText("Guardar ficheros");
        BtnGuardar.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        BtnGuardar.setEnabled(false);
        BtnGuardar.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnGuardarActionPerformed(evt);
            }
        });

        BtnMostrarDom.setBackground(new java.awt.Color(102, 255, 102));
        BtnMostrarDom.setText("Muestra DOM");
        BtnMostrarDom.setEnabled(false);
        BtnMostrarDom.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnMostrarDomActionPerformed(evt);
            }
        });

        jPanelDatos.setEnabled(false);

        jLabel1.setText("Marca");

        jTextFieldMarca.setEditable(false);
        jTextFieldMarca.addKeyListener(new java.awt.event.KeyAdapter()
        {
            public void keyPressed(java.awt.event.KeyEvent evt)
            {
                jTextFieldMarcaKeyPressed(evt);
            }
        });

        jLabel2.setText("Modelo");

        jLabel3.setText("Cilindrada");

        jTextFieldCilindrada.setEditable(false);
        jTextFieldCilindrada.addKeyListener(new java.awt.event.KeyAdapter()
        {
            public void keyReleased(java.awt.event.KeyEvent evt)
            {
                jTextFieldCilindradaKeyReleased(evt);
            }
        });

        jTextFieldModelo.setEditable(false);
        jTextFieldModelo.addKeyListener(new java.awt.event.KeyAdapter()
        {
            public void keyPressed(java.awt.event.KeyEvent evt)
            {
                jTextFieldModeloKeyPressed(evt);
            }
        });

        jLabel4.setText("Potencia");

        jTextFieldPotencia.setEditable(false);
        jTextFieldPotencia.addKeyListener(new java.awt.event.KeyAdapter()
        {
            public void keyPressed(java.awt.event.KeyEvent evt)
            {
                jTextFieldPotenciaKeyPressed(evt);
            }
        });

        jLabel5.setText("Cilindros");

        jTextFieldCilindros.setEditable(false);
        jTextFieldCilindros.addKeyListener(new java.awt.event.KeyAdapter()
        {
            public void keyPressed(java.awt.event.KeyEvent evt)
            {
                jTextFieldCilindrosKeyPressed(evt);
            }
        });

        jLabel6.setText("cc");

        jLabel7.setText("cv");

        jLabel8.setText("Refrigeracion");

        jTextFieldRefrigeracion.setEditable(false);
        jTextFieldRefrigeracion.addKeyListener(new java.awt.event.KeyAdapter()
        {
            public void keyPressed(java.awt.event.KeyEvent evt)
            {
                jTextFieldRefrigeracionKeyPressed(evt);
            }
        });

        jLabel9.setText("Precio");

        jTextFieldPrecio.setEditable(false);
        jTextFieldPrecio.addKeyListener(new java.awt.event.KeyAdapter()
        {
            public void keyPressed(java.awt.event.KeyEvent evt)
            {
                jTextFieldPrecioKeyPressed(evt);
            }
        });

        jPanelImage.setEnabled(false);

        javax.swing.GroupLayout jPanelImageLayout = new javax.swing.GroupLayout(jPanelImage);
        jPanelImage.setLayout(jPanelImageLayout);
        jPanelImageLayout.setHorizontalGroup(
            jPanelImageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 300, Short.MAX_VALUE)
        );
        jPanelImageLayout.setVerticalGroup(
            jPanelImageLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 200, Short.MAX_VALUE)
        );

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 14)); // NOI18N
        jLabel10.setText("€");

        javax.swing.GroupLayout jPanelDatosLayout = new javax.swing.GroupLayout(jPanelDatos);
        jPanelDatos.setLayout(jPanelDatosLayout);
        jPanelDatosLayout.setHorizontalGroup(
            jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDatosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel4)
                    .addComponent(jLabel5)
                    .addComponent(jLabel8)
                    .addComponent(jLabel9))
                .addGap(18, 18, 18)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldMarca)
                    .addGroup(jPanelDatosLayout.createSequentialGroup()
                        .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jTextFieldModelo, javax.swing.GroupLayout.PREFERRED_SIZE, 233, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanelDatosLayout.createSequentialGroup()
                                .addComponent(jTextFieldCilindrada, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel6))
                            .addGroup(jPanelDatosLayout.createSequentialGroup()
                                .addComponent(jTextFieldPotencia, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel7))
                            .addComponent(jTextFieldCilindros, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jTextFieldRefrigeracion, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(jPanelDatosLayout.createSequentialGroup()
                                .addComponent(jTextFieldPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, 100, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jLabel10)))
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap(46, Short.MAX_VALUE))
            .addGroup(jPanelDatosLayout.createSequentialGroup()
                .addGap(14, 14, 14)
                .addComponent(jPanelImage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanelDatosLayout.setVerticalGroup(
            jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanelDatosLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel1)
                    .addComponent(jTextFieldMarca, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldModelo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel2))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel6, javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldCilindrada, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLabel4)
                    .addComponent(jTextFieldPotencia, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel7))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextFieldCilindros, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jTextFieldRefrigeracion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel8))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanelDatosLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jTextFieldPrecio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel10))
                    .addComponent(jLabel9))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 37, Short.MAX_VALUE)
                .addComponent(jPanelImage, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        BtnMostrarTexto.setBackground(new java.awt.Color(102, 255, 255));
        BtnMostrarTexto.setText("Muestra Texto");
        BtnMostrarTexto.setEnabled(false);
        BtnMostrarTexto.setName(""); // NOI18N
        BtnMostrarTexto.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnMostrarTextoActionPerformed(evt);
            }
        });

        BtnMostrarBinario.setBackground(new java.awt.Color(102, 255, 255));
        BtnMostrarBinario.setText("Muestra Binario");
        BtnMostrarBinario.setEnabled(false);
        BtnMostrarBinario.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnMostrarBinarioActionPerformed(evt);
            }
        });

        BtnMostrarSax.setBackground(new java.awt.Color(102, 255, 102));
        BtnMostrarSax.setText("Muestra SAX");
        BtnMostrarSax.setEnabled(false);
        BtnMostrarSax.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnMostrarSaxActionPerformed(evt);
            }
        });

        BtnAnyadir.setText("Añadir");
        BtnAnyadir.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        BtnAnyadir.setEnabled(false);
        BtnAnyadir.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnAnyadirActionPerformed(evt);
            }
        });

        BtnMostrarArray.setBackground(new java.awt.Color(102, 255, 255));
        BtnMostrarArray.setText("Mostrar Array");
        BtnMostrarArray.setEnabled(false);
        BtnMostrarArray.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnMostrarArrayActionPerformed(evt);
            }
        });

        BtnMostrarXml.setBackground(new java.awt.Color(102, 255, 102));
        BtnMostrarXml.setText("Mostrar XML");
        BtnMostrarXml.setEnabled(false);
        BtnMostrarXml.setRequestFocusEnabled(false);
        BtnMostrarXml.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnMostrarXmlActionPerformed(evt);
            }
        });

        BtnCancelar.setText("Cancelar");
        BtnCancelar.setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
        BtnCancelar.setEnabled(false);
        BtnCancelar.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                BtnCancelarActionPerformed(evt);
            }
        });

        jMenu3.setText("Ficheros");

        MenuAbrirDom.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_D, java.awt.event.InputEvent.CTRL_MASK));
        MenuAbrirDom.setText("Abrir XML_DOM");
        MenuAbrirDom.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                MenuAbrirDomActionPerformed(evt);
            }
        });
        jMenu3.add(MenuAbrirDom);

        MenuAbrirSax.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.CTRL_MASK));
        MenuAbrirSax.setText("Abrir XML_SAX");
        MenuAbrirSax.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                MenuAbrirSaxActionPerformed(evt);
            }
        });
        jMenu3.add(MenuAbrirSax);
        jMenu3.add(jSeparator1);

        MenuAbrirTexto.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_T, java.awt.event.InputEvent.CTRL_MASK));
        MenuAbrirTexto.setText("Abrir Fichero Texto");
        MenuAbrirTexto.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                MenuAbrirTextoActionPerformed(evt);
            }
        });
        jMenu3.add(MenuAbrirTexto);

        MenuAbrirBinario.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_B, java.awt.event.InputEvent.CTRL_MASK));
        MenuAbrirBinario.setText("Abrir Fichero Binario");
        MenuAbrirBinario.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                MenuAbrirBinarioActionPerformed(evt);
            }
        });
        jMenu3.add(MenuAbrirBinario);

        jMenuBar1.add(jMenu3);

        jMenu1.setText("BDR");

        MenuCrearBD.setText("Crear");
        jMenu1.add(MenuCrearBD);

        MenuConectarBD.setText("Conectar...");
        jMenu1.add(MenuConectarBD);

        MenuDesconectarBD.setText("Desconectar");
        jMenu1.add(MenuDesconectarBD);

        MenuEjecutarComandoBD.setText("Ejecutar comando");
        jMenu1.add(MenuEjecutarComandoBD);

        MenuRenombrarBD.setText("Renombrar");
        jMenu1.add(MenuRenombrarBD);

        MenuPropiedadesBD.setText("Propiedades");
        jMenu1.add(MenuPropiedadesBD);

        jMenuBar1.add(jMenu1);

        MenuSalir.setText("Salir");

        MenuSalirSalir.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        MenuSalirSalir.setText("Salir");
        MenuSalirSalir.addActionListener(new java.awt.event.ActionListener()
        {
            public void actionPerformed(java.awt.event.ActionEvent evt)
            {
                MenuSalirSalirActionPerformed(evt);
            }
        });
        MenuSalir.add(MenuSalirSalir);

        jMenuBar1.add(MenuSalir);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jLabelmensaje, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(BtnMostrarDom, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(BtnMostrarSax, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(BtnMostrarXml, javax.swing.GroupLayout.DEFAULT_SIZE, 158, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(BtnMostrarTexto, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(BtnMostrarBinario, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addComponent(BtnMostrarArray, javax.swing.GroupLayout.DEFAULT_SIZE, 161, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButtonMostrarDOM, javax.swing.GroupLayout.PREFERRED_SIZE, 1, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(2, 2, 2))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 643, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanelDatos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(BtnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(12, 12, 12)
                                .addComponent(BtnAnyadir, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(BtnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addGap(12, 12, 12)))
                .addContainerGap())
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jLabelmensaje)
                        .addGap(13, 13, 13)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(BtnMostrarDom, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(BtnMostrarSax, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(BtnMostrarXml, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(BtnMostrarTexto, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(BtnMostrarBinario, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(18, 18, 18)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addGroup(layout.createSequentialGroup()
                                .addComponent(jPanelDatos, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                    .addComponent(BtnGuardar, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(BtnAnyadir, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)
                                    .addComponent(BtnCancelar, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
                            .addComponent(jScrollPane1)))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(28, 28, 28)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButtonMostrarDOM)
                            .addComponent(BtnMostrarArray, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(46, Short.MAX_VALUE))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    // Método imborrable
    private void jButtonMostrarDOMActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_jButtonMostrarDOMActionPerformed
    {//GEN-HEADEREND:event_jButtonMostrarDOMActionPerformed

//        String salida= "";
//        salida= gesDOM.recorrerDOMyMostrar();
//        this.jTextAreaDOM.setText(salida);

    }//GEN-LAST:event_jButtonMostrarDOMActionPerformed

    private void BtnGuardarActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_BtnGuardarActionPerformed
    {//GEN-HEADEREND:event_BtnGuardarActionPerformed
        String marca, modelo, refrigeracion, imagen;
        int cilindrada, cilindros;
        double potencia, precio;

        try {
            marca = jTextFieldMarca.getText();
            modelo = jTextFieldModelo.getText();
            if (marca.equals("") || modelo.equals("")) {
                JOptionPane.showMessageDialog(null, "Debe introducir la marca y el modelo");
                return;
            }
            refrigeracion = jTextFieldRefrigeracion.getText();
            //pendiente de solucionar imagen
            imagen = "Falta imagen";
            cilindrada = Integer.parseInt(jTextFieldCilindrada.getText().equals("") ? "0" : jTextFieldCilindrada.getText());
            cilindros = Integer.parseInt(jTextFieldCilindros.getText().equals("") ? "0" : jTextFieldCilindros.getText());
            potencia = Double.parseDouble(jTextFieldPotencia.getText().equals("") ? "0" : jTextFieldPotencia.getText());
            precio = Double.parseDouble(jTextFieldPrecio.getText().equals("") ? "0" : jTextFieldPrecio.getText());

            Moto moto = new Moto(marca, modelo, cilindrada, potencia, cilindros, refrigeracion, precio, imagen);
            jTextFieldMarca.setText("");
            jTextFieldModelo.setText("");
            jTextFieldRefrigeracion.setText("");
            //pendiente de solucionar imagen
            jTextFieldCilindrada.setText("");
            jTextFieldCilindros.setText("");
            jTextFieldPotencia.setText("");
            jTextFieldPrecio.setText("");
            try {

                myManager.Add(moto);
                String filenameAux = filename.substring(0, filename.length() - 4);
                myManager.writeBinaryFile(filenameAux + ".dat");
                myManager.writeTextFile(filenameAux + ".txt");
                myManager.writeXML(filenameAux + ".xml");
                BtnGuardar.setEnabled(false);
                BtnAnyadir.setEnabled(true);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(null, "Error guardando la nueva moto");
            }

        } catch (NumberFormatException numberFormatException) {
            JOptionPane.showMessageDialog(null, "Compruebe los datos introcidos.\n Cilindrada, potencia, cilindros y precio deben ser números.\n Use '.' como separador decimal");
        }


    }//GEN-LAST:event_BtnGuardarActionPerformed

    /**
     * Método para mostrar un archivo xml con DOM
     * @param evt 
     */
    private void BtnMostrarDomActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_BtnMostrarDomActionPerformed
    {//GEN-HEADEREND:event_BtnMostrarDomActionPerformed
        String cadena = "";

        //Show on screen the xml file
        cadena += "\t\tCOLECCION DE MOTOS. Fichero XML\n\n";

        cadena += myManager.showXML(filename);

        this.jTextArea.setText(cadena);

        BtnGuardar.setEnabled(false);
        BtnAnyadir.setEnabled(true);
        BtnCancelar.setEnabled(false);
    }//GEN-LAST:event_BtnMostrarDomActionPerformed

    /**
     * Método para añadir los datos de los textbox al array de motos
     * @param evt 
     */
    private void BtnAnyadirActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_BtnAnyadirActionPerformed
    {//GEN-HEADEREND:event_BtnAnyadirActionPerformed
        jTextFieldMarca.setEditable(true);
        jTextFieldModelo.setEditable(true);
        jTextFieldCilindrada.setEditable(true);
        jTextFieldCilindros.setEditable(true);
        jTextFieldPotencia.setEditable(true);
        jTextFieldPrecio.setEditable(true);
        jTextFieldRefrigeracion.setEditable(true);
//        jTextFieldIma.setEnabled(true);

        BtnGuardar.setEnabled(true);
        BtnAnyadir.setEnabled(false);
        BtnCancelar.setEnabled(true);

        jTextFieldMarca.requestFocus(true);
    }//GEN-LAST:event_BtnAnyadirActionPerformed

    /**
     * Método para mostrar el archivo xml en modo texto
     * @param evt 
     */
    private void BtnMostrarTextoActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_BtnMostrarTextoActionPerformed
    {//GEN-HEADEREND:event_BtnMostrarTextoActionPerformed
        String cadena = "\t\tCOLECCION DE MOTOS. Fichero de Texto\n\n";
        cadena += myManager.showTextFile(filename);

        this.jTextArea.setText(cadena);
        BtnGuardar.setEnabled(false);
        BtnAnyadir.setEnabled(true);
        BtnCancelar.setEnabled(false);
    }//GEN-LAST:event_BtnMostrarTextoActionPerformed

    /**
     * Método para mostrar el archivo xml con SAX
     * @param evt 
     */
    private void BtnMostrarSaxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_BtnMostrarSaxActionPerformed
    {//GEN-HEADEREND:event_BtnMostrarSaxActionPerformed
        String cadena = "\t\tCOLECCION DE MOTOS. Lectura SAX\n\n";
        cadena += myManager.ReadXML_Sax(filename);

        this.jTextArea.setText(cadena);
        BtnGuardar.setEnabled(false);
        BtnAnyadir.setEnabled(true);
        BtnCancelar.setEnabled(false);
    }//GEN-LAST:event_BtnMostrarSaxActionPerformed

    /**
     * Método para mostrar los datos del archivo binario
     * @param evt 
     */
    private void BtnMostrarBinarioActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_BtnMostrarBinarioActionPerformed
    {//GEN-HEADEREND:event_BtnMostrarBinarioActionPerformed
        String cadena = "";
        // Show on jtextArea the binary file
        cadena += "\t\tCOLECCION DE MOTOS. Fichero Binario\n\n";
        try {
            // myManager.writeBinaryFile(filename);
            myManager.readBinaryFile(filename);
        } catch (IOException ex) {
            // Logger.getLogger(Principal.class.getName()).log(Level.SEVERE, null, ex);
            // EXCEPCIÓN MSG BOX

        }
        cadena += myManager.showColection();

        this.jTextArea.setText(cadena);
        BtnGuardar.setEnabled(false);
        BtnAnyadir.setEnabled(true);
        BtnCancelar.setEnabled(false);
    }//GEN-LAST:event_BtnMostrarBinarioActionPerformed

    /**
     * Métdodo para mostrar el archivo de texto de motos
     * @param evt 
     */
    private void MenuAbrirTextoActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_MenuAbrirTextoActionPerformed
    {//GEN-HEADEREND:event_MenuAbrirTextoActionPerformed
        filename = "Motos.txt";
        BtnMostrarBinario.setEnabled(false);
        BtnMostrarDom.setEnabled(false);
        BtnMostrarSax.setEnabled(false);
        BtnMostrarTexto.setEnabled(true);
        BtnMostrarArray.setEnabled(true);
        BtnMostrarXml.setEnabled(false);

        flagIsTexto = true;

        jLabelmensaje.setText("Fichero abierto -> " + filename);
    }//GEN-LAST:event_MenuAbrirTextoActionPerformed

    /**
     * Método para establecer los botones que estan activos al pulsar DOM
     * @param evt 
     */
    private void MenuAbrirDomActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_MenuAbrirDomActionPerformed
    {//GEN-HEADEREND:event_MenuAbrirDomActionPerformed
        filename = "Motos.xml";
        BtnMostrarBinario.setEnabled(false);
        BtnMostrarDom.setEnabled(true);
        BtnMostrarSax.setEnabled(false);
        BtnMostrarTexto.setEnabled(false);
        BtnMostrarArray.setEnabled(false);
        BtnMostrarXml.setEnabled(true);

        jLabelmensaje.setText("Fichero abierto -> " + filename);
    }//GEN-LAST:event_MenuAbrirDomActionPerformed

    /**
     * Método para establecer los botones que estan activos al pulsar SAX
     * @param evt 
     */
    private void MenuAbrirSaxActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_MenuAbrirSaxActionPerformed
    {//GEN-HEADEREND:event_MenuAbrirSaxActionPerformed
        filename = "Motos.xml";
        BtnMostrarBinario.setEnabled(false);
        BtnMostrarDom.setEnabled(false);
        BtnMostrarSax.setEnabled(true);
        BtnMostrarTexto.setEnabled(false);
        BtnMostrarArray.setEnabled(false);
        BtnMostrarXml.setEnabled(true);

        jLabelmensaje.setText("Fichero abierto -> " + filename);
    }//GEN-LAST:event_MenuAbrirSaxActionPerformed

    /**
     * Método para establecer los botones que estan activos al pulsar Binario
     * @param evt 
     */
    private void MenuAbrirBinarioActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_MenuAbrirBinarioActionPerformed
    {//GEN-HEADEREND:event_MenuAbrirBinarioActionPerformed
        filename = "Motos.dat";
        BtnMostrarBinario.setEnabled(true);
        BtnMostrarDom.setEnabled(false);
        BtnMostrarSax.setEnabled(false);
        BtnMostrarTexto.setEnabled(false);
        BtnMostrarArray.setEnabled(true);
        BtnMostrarXml.setEnabled(false);

        flagIsTexto = false;
        jLabelmensaje.setText("Fichero abierto -> " + filename);
    }//GEN-LAST:event_MenuAbrirBinarioActionPerformed

    /**
     * Método para mostrar el array en el textarea
     * @param evt 
     */
    private void BtnMostrarArrayActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_BtnMostrarArrayActionPerformed
    {//GEN-HEADEREND:event_BtnMostrarArrayActionPerformed
        String cadena = "\t\tCOLECCION DE MOTOS. Array de Motos\n\n";

        if (flagIsTexto) {
            myManager.readTextFile(filename);
        } else {
            try {
                myManager.readBinaryFile(filename);
            } catch (IOException ex) {
                Logger.getLogger(JFrameFicheros.class.getName()).log(Level.SEVERE, null, ex);
                // MSG BOX EXCEPCIÓN
            }
        }

        cadena += myManager.showColection();

        this.jTextArea.setText(cadena);
        BtnGuardar.setEnabled(false);
        BtnAnyadir.setEnabled(true);
        BtnCancelar.setEnabled(false);
    }//GEN-LAST:event_BtnMostrarArrayActionPerformed

    /**
     * Método para mostrar el xml en el textarea
     * @param evt 
     */
    private void BtnMostrarXmlActionPerformed(java.awt.event.ActionEvent evt)//GEN-FIRST:event_BtnMostrarXmlActionPerformed
    {//GEN-HEADEREND:event_BtnMostrarXmlActionPerformed
        String cadena = "\t\tCOLECCION DE MOTOS. Archivo XML\n\n";
        cadena += myManager.showTextFile(filename);

        this.jTextArea.setText(cadena);
        BtnGuardar.setEnabled(false);
        BtnAnyadir.setEnabled(true);
        BtnCancelar.setEnabled(false);
    }//GEN-LAST:event_BtnMostrarXmlActionPerformed

    /**
     * Menú Salir, cierra la aplicación
     * @param evt 
     */
    private void MenuSalirSalirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MenuSalirSalirActionPerformed
        int dialogResult = JOptionPane.showConfirmDialog(null, "¿Estás seguro de que quieres salir?", "Warning", JOptionPane.YES_NO_OPTION);

        if (dialogResult == JOptionPane.YES_OPTION) {
            System.exit(0);
        }
    }//GEN-LAST:event_MenuSalirSalirActionPerformed

    // Métodos para avisar al usuario que tiene que pulsar añadir para acceder
    // a los TextBox.
    private void jTextFieldMarcaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldMarcaKeyPressed
        if (!BtnGuardar.isEnabled()) {
            JOptionPane.showMessageDialog(null, "Pulse el botón Añadir para agregar nuevos datos");
        }
    }//GEN-LAST:event_jTextFieldMarcaKeyPressed

    private void jTextFieldModeloKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldModeloKeyPressed
        if (!BtnGuardar.isEnabled()) {
            JOptionPane.showMessageDialog(null, "Pulse el botón Añadir para agregar nuevos datos");
        }
    }//GEN-LAST:event_jTextFieldModeloKeyPressed

    private void jTextFieldCilindradaKeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldCilindradaKeyReleased
        if (!BtnGuardar.isEnabled()) {
            JOptionPane.showMessageDialog(null, "Pulse el botón Añadir para agregar nuevos datos");
        }
    }//GEN-LAST:event_jTextFieldCilindradaKeyReleased

    private void jTextFieldPotenciaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldPotenciaKeyPressed
        if (!BtnGuardar.isEnabled()) {
            JOptionPane.showMessageDialog(null, "Pulse el botón Añadir para agregar nuevos datos");
        }
    }//GEN-LAST:event_jTextFieldPotenciaKeyPressed

    private void jTextFieldCilindrosKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldCilindrosKeyPressed
        if (!BtnGuardar.isEnabled()) {
            JOptionPane.showMessageDialog(null, "Pulse el botón Añadir para agregar nuevos datos");
        }
    }//GEN-LAST:event_jTextFieldCilindrosKeyPressed

    private void jTextFieldRefrigeracionKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldRefrigeracionKeyPressed
        if (!BtnGuardar.isEnabled()) {
            JOptionPane.showMessageDialog(null, "Pulse el botón Añadir para agregar nuevos datos");
        }
    }//GEN-LAST:event_jTextFieldRefrigeracionKeyPressed

    private void jTextFieldPrecioKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextFieldPrecioKeyPressed
        if (!BtnGuardar.isEnabled()) {
            JOptionPane.showMessageDialog(null, "Pulse el botón Añadir para agregar nuevos datos");
        }
    }//GEN-LAST:event_jTextFieldPrecioKeyPressed

    /**
     * Método que limpia todos los textbox
     * @param evt 
     */
    private void BtnCancelarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_BtnCancelarActionPerformed
        jTextFieldMarca.setText("");
        jTextFieldModelo.setText("");
        jTextFieldRefrigeracion.setText("");
        //pendiente de solucionar imagen
        jTextFieldCilindrada.setText("");
        jTextFieldCilindros.setText("");
        jTextFieldPotencia.setText("");
        jTextFieldPrecio.setText("");

        BtnGuardar.setEnabled(false);
        BtnAnyadir.setEnabled(true);
        BtnCancelar.setEnabled(false);
    }//GEN-LAST:event_BtnCancelarActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(JFrameFicheros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(JFrameFicheros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(JFrameFicheros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(JFrameFicheros.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {
            @Override
            public void run() {
                new JFrameFicheros().setVisible(true);
            }
        });
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton BtnAnyadir;
    private javax.swing.JButton BtnCancelar;
    private javax.swing.JButton BtnGuardar;
    private javax.swing.JButton BtnMostrarArray;
    private javax.swing.JButton BtnMostrarBinario;
    private javax.swing.JButton BtnMostrarDom;
    private javax.swing.JButton BtnMostrarSax;
    public javax.swing.JButton BtnMostrarTexto;
    private javax.swing.JButton BtnMostrarXml;
    private javax.swing.JMenuItem MenuAbrirBinario;
    private javax.swing.JMenuItem MenuAbrirDom;
    private javax.swing.JMenuItem MenuAbrirSax;
    private javax.swing.JMenuItem MenuAbrirTexto;
    private javax.swing.JMenuItem MenuConectarBD;
    private javax.swing.JMenuItem MenuCrearBD;
    private javax.swing.JMenuItem MenuDesconectarBD;
    private javax.swing.JMenuItem MenuEjecutarComandoBD;
    private javax.swing.JMenuItem MenuPropiedadesBD;
    private javax.swing.JMenuItem MenuRenombrarBD;
    private javax.swing.JMenu MenuSalir;
    private javax.swing.JMenuItem MenuSalirSalir;
    private javax.swing.JButton jButtonMostrarDOM;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JLabel jLabelmensaje;
    private javax.swing.JMenu jMenu1;
    private javax.swing.JMenu jMenu2;
    private javax.swing.JMenu jMenu3;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JPanel jPanelDatos;
    private javax.swing.JPanel jPanelImage;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JTextArea jTextArea;
    private javax.swing.JTextField jTextFieldCilindrada;
    private javax.swing.JTextField jTextFieldCilindros;
    private javax.swing.JTextField jTextFieldMarca;
    private javax.swing.JTextField jTextFieldModelo;
    private javax.swing.JTextField jTextFieldPotencia;
    private javax.swing.JTextField jTextFieldPrecio;
    private javax.swing.JTextField jTextFieldRefrigeracion;
    // End of variables declaration//GEN-END:variables

    public void setMenuAbrirBinario() {
        this.MenuAbrirBinarioActionPerformed(null);
    }

    public void setMenuAbrirDom() {
        this.MenuAbrirDomActionPerformed(null);
    }

    public void setMenuAbrirSax() {
        this.MenuAbrirSaxActionPerformed(null);
    }

    public void setMenuAbrirTexto() {
        this.MenuAbrirTextoActionPerformed(null);
    }
}
